<?php
/**
 * Ganglib
 *
 * LICENSE
 *
 * This source file is subject to the GNU Lesser Generak Public license.
 * 
 * It is available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/lgpl.html
 *
 * @category    Ganglib
 * @package    Div_Db_Distributor_Strategy_PDO
 * @copyright  Copyright (c) 2008 Ganglib project members (http://www.code.google.com/p/ganglib)
 * @license     http://www.gnu.org/licenses/lgpl.html
 */
 
/**
 * Vertical Strategy
 * 
 * Strategy decides which schema to choose for table
 * 
 * @package    Div_Db_Distributor_Strategy_PDO
 * @copyright  Copyright (c) 2008 Ganglib project members (http://www.code.google.com/p/ganglib)
 * @license     http://www.gnu.org/licenses/lgpl.html
 */
require_once('Div/Db/Distributor/Strategy/PDO/Abstract.php'); 
class Div_Db_Distributor_Strategy_PDO_Vertical extends Div_Db_Distributor_Strategy_PDO_Abstract 
{
	/**
	 * Query database
	 *
	 * @param Div_Db_Query $query
	 * @return PDO_Statement
	 */
	public function distributeQuery(Div_Db_Query $query)
	{
		$modelArray = $query->toModelArray();
		if(isset($this->_config->vertical->from->{$modelArray['from'][0]}))
			$schema = $this->_config->vertical->from->{$modelArray['from'][0]};
		else
			$schema = $this->_config->vertical->default;

		$connection = $this->connect($schema);
		
		return $this->runQuery($connection, $query);
	}
	
}